{
 "metadata": {
  "name": "04-Simple RayTraces"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from pyoptools.all import *"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Crear un sistema sencillo con una lente"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L1=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "S=System(complist=[(L1,(0,0,100),(0,0,0))],n=1)\n",
      "R=[Ray(pos=(0,0,0),dir=(0,.2,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(0,-.2,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(.2,0,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(-.2,0,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(0,0,1),wavelength=.650)]\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,0,100),size=(200,100),scale=4,rot=[(0,pi/2,0),(pi/20,-pi/10,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Mirar algunos parametros de la lente"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L1.paraxial_constants() #Distancia focal efectiva, punto focal anterior, punto focal posterior"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Armar un sistema con 2 lentes"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "L3=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "\n",
      "S=System(complist=[(L2,(0,0,100),(0,0,0)),(L3,(0,0,120),(0,0,0)) ],n=1)\n",
      "R=[Ray(pos=(0,0,0),dir=(0,.2,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(0,-.2,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(.2,0,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(-.2,0,1),wavelength=.650),\n",
      "   Ray(pos=(0,0,0),dir=(0,0,1),wavelength=.650)]\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,0,100),size=(200,100),scale=4,rot=[(0,pi/2,0),(pi/20,-pi/10,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "L3=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "\n",
      "S=System(complist=[(L2,(0,0,100),(0,0,0)),(L3,(0,0,120),(0,0,0)) ],n=1)\n",
      "R=[]\n",
      "\n",
      "for x in range(-30,40,10):\n",
      "    for y in range(-30,40,10):\n",
      "        R.append(Ray(pos=(0,0,0),dir=(x,y,100),wavelength=.650))\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,0,100),size=(200,100),scale=4,rot=[(0,pi/2,0),(pi/20,-pi/10,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "L3=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "\n",
      "C=CCD()\n",
      "\n",
      "S=System(complist=[(L2,(0,0,100),(0,0,0)),(L3,(0,0,120),(0,0,0)),(C,(0,0,215),(0,0,0)) ],n=1)\n",
      "R=[]\n",
      "\n",
      "for x in range(-25,35,5):\n",
      "    for y in range(-25,35,5):\n",
      "        R.append(Ray(pos=(0,0,0),dir=(x,y,100),wavelength=.650))\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,0,100),size=(250,100),scale=4,rot=[(0,pi/2,0),(pi/20,-pi/10,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "spot_diagram(C)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Un espectroscopio con prisma"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L=60\n",
      "h=L/2.*cos(pi/3.)\n",
      "h1=L/2*sin(pi/3)\n",
      "S1=Plane(shape=Rectangular((L,L)))\n",
      "S2=Plane(shape=Rectangular((L,L)))\n",
      "S3=Plane(shape=Rectangular((L,L)))\n",
      "\n",
      "T1=Plane(shape=Triangular(((2*h,h1),(-2*h,h1),(0,-h1))))\n",
      "T2=Plane(shape=Triangular(((2*h,h1),(-2*h,h1),(0,-h1))))\n",
      "P=Component(surflist=[(S1,(0,h1,0),(pi/2,0,0)),\n",
      "                      (S2,(0,0,h),(pi/6,0,0)),\n",
      "                      (S3,(0,0,-h),(-pi/6,0,0)), \n",
      "                      (T1,(L/2,0,0),(0,pi/2,0)),\n",
      "                      (T2,(-L/2,0,0),(0,pi/2,0))\n",
      "                      ], \n",
      "                      material=schott[\"BK7\"])\n",
      "\n",
      "L=SphericalLens(radius=25,curvature_s1=1./200.,curvature_s2=-1./200,thickness=10,material=schott[\"BK7\"])\n",
      "C=CCD()\n",
      "PCCD=243.5\n",
      "S=System(complist=[(P,(0,0,0),(0,0,0)),\n",
      "                   (L,(0,.35*60,60),(-0.357,0,0)),\n",
      "                   (C,(0,.35*PCCD,PCCD),(-0.357,0,0))],n=1)\n",
      "\n",
      "R=[]\n",
      "\n",
      "for x in range (-10,15,5):\n",
      "    for y in range (-10,15,5):\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.45))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.5))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.55))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.60))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.65))\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "\n",
      "plot3D(S,center=(0,.35*60,60),size=(500,200),scale=2,rot=[(0,pi/2+.2,0),(-.1,0,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "spot_diagram_c(C)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plot3D(S,center=(0,.35*PCCD,PCCD),size=(50,30),scale=10,rot=[(0,pi/2+.1,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Otro espectroscopio con prisma"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L=60\n",
      "h=L/2.*cos(pi/3.)\n",
      "h1=L/2*sin(pi/3)\n",
      "S1=Plane(shape=Rectangular((L,L)))\n",
      "S2=Plane(shape=Rectangular((L,L)))\n",
      "S3=Plane(shape=Rectangular((L,L)))\n",
      "\n",
      "T1=Plane(shape=Triangular(((2*h,h1),(-2*h,h1),(0,-h1))))\n",
      "T2=Plane(shape=Triangular(((2*h,h1),(-2*h,h1),(0,-h1))))\n",
      "P=Component(surflist=[(S1,(0,h1,0),(pi/2,0,0)),\n",
      "                      (S2,(0,0,h),(pi/6,0,0)),\n",
      "                      (S3,(0,0,-h),(-pi/6,0,0)), \n",
      "                      (T1,(L/2,0,0),(0,pi/2,0)),\n",
      "                      (T2,(-L/2,0,0),(0,pi/2,0))\n",
      "                      ], \n",
      "                      material=schott[\"BK7\"])\n",
      "\n",
      "S4=Cylindrical(shape=Circular(radius=25),curvature=1./200)\n",
      "S5=Cylindrical(shape=Circular(radius=25),curvature=-1./200)\n",
      "\n",
      "L=Component(surflist=[(S5,(0,0,5),(0,0,pi/2)),\n",
      "                      (S4,(0,0,-5),(0,0,pi/2))\n",
      "                      ], \n",
      "                      material=schott[\"BK7\"])\n",
      "\n",
      "\n",
      "C=CCD()\n",
      "PCCD=243.5\n",
      "S=System(complist=[(P,(0,0,0),(0,0,0)),\n",
      "                   (L,(0,.35*60,60),(-0.357,0,0)),\n",
      "                   (C,(0,.35*PCCD,PCCD),(-0.357,0,0))],n=1)\n",
      "\n",
      "R=[]\n",
      "\n",
      "for x in range (-5,6,1):\n",
      "    for y in range (-5,6,2):\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.45))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.5))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.55))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.60))\n",
      "        R.append(Ray(pos=(x,y+35,-100),dir=(0,-.35,1),wavelength=.65))\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "\n",
      "plot3D(S,center=(0,.35*60,60),size=(500,200),scale=2,rot=[(0,pi/2+.2,0),(-.1,0,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "spot_diagram_c(C)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plot3D(S,center=(0,.35*PCCD,PCCD),size=(50,30),scale=10,rot=[(0,pi/2+.1,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Colocando aperturas"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L2=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "L3=SphericalLens(radius=25,curvature_s1=1./100.,curvature_s2=-1./100,thickness=10,material=schott[\"BK7\"])\n",
      "\n",
      "C=CCD()\n",
      "\n",
      "AP=Aperture(shape=Rectangular(size=(50,50)),ap_shape=Circular(radius=15))\n",
      "#AP=Aperture(shape=Rectangular(size=(50,50)),ap_shape=Triangular(coord=((0,15),(15,-15),(-15,-15))))\n",
      "\n",
      "APC=Component(surflist=[(AP,(0,0,0),(0,0,0))])\n",
      "\n",
      "S=System(complist=[(L2,(0,0,100),(0,0,0)),\n",
      "                   (L3,(0,0,120),(0,0,0)),\n",
      "                   (C,(0,0,215),(0,0,0)),\n",
      "                   (APC,(0,0,110),(0,0,0)),\n",
      "                   ],n=1)\n",
      "R=[]\n",
      "\n",
      "for x in range(-25,35,2):\n",
      "    for y in range(-25,35,2):\n",
      "        R.append(Ray(pos=(0,0,0),dir=(x,y,100),wavelength=.650))\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,0,100),size=(250,100),scale=4,rot=[(0,pi/4,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Reflecci\u00f3n total interna"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "P0=RightAnglePrism(width=50,height=50,material=schott[\"BK7\"],reflectivity=0)\n",
      "P1=RightAnglePrism(width=50,height=50,material=schott[\"BK7\"],reflectivity=0)\n",
      "\n",
      "S=System(complist=[(P0,(0,0,20),(0,0,pi/2)),(P1,(0,80,20),(0,0,-pi/2))],n=1)\n",
      "\n",
      "R=[]\n",
      "for x in range (-5,6,2):\n",
      "    for y in range (-5,6,2):\n",
      "        R.append(Ray(pos=(x,y,-100),dir=(0,0,1),wavelength=.45))\n",
      "        \n",
      "for x in range (-5,6,2):\n",
      "    for z in range (35,45,2):\n",
      "        R.append(Ray(pos=(x,100,z),dir=(0,-1,0),wavelength=.540))\n",
      "        \n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,40,-10),size=(200,150),scale=4,rot=[(0,-pi/2,0)])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Multiples fuentes y distintos tipos de fuentes"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "r_b=point_source_r(origin=(0.,0.,0.),direction=(0.,0.,0),span=pi/256\n",
      "                   ,num_rays=10,wavelength=0.470, label=\"blue\")\n",
      "\n",
      "r_b1=point_source_r(origin=(30.,0.,0.),direction=(0.,0.,0),span=pi/256\n",
      "                   ,num_rays=10,wavelength=0.470, label=\"blue1\")\n",
      "\n",
      "\n",
      "#r_b=point_source_p(origin=(0.,0.,0.),direction=(0.,0.,0),span=pi/256\n",
      "#                   ,num_rays=(10,10),wavelength=0.470, label=\"blue\")\n",
      "\n",
      "#r_b1=point_source_p(origin=(30.,0.,0.),direction=(0.,0.,0),span=pi/256\n",
      "#                   ,num_rays=(10,10),wavelength=0.470, label=\"blue1\")\n",
      "\n",
      "#r_b=point_source_c(origin=(0.,0.,0.),direction=(0.,0.,0),span=(pi/256,pi/256)\n",
      "#                   ,num_rays=(10,10),wavelength=0.470, label=\"blue\")\n",
      "\n",
      "#r_b1=point_source_c(origin=(30.,0.,0.),direction=(0.,0.,0),span=(pi/256,pi/256)\n",
      "#                   ,num_rays=(10,10),wavelength=0.470, label=\"blue1\")\n",
      "\n",
      "\n",
      "\n",
      "N_BK7=schott['BK7']\n",
      "SF5=schott['SF5']\n",
      "#Dobletes 32-327 Edmund Scientific\n",
      "DB1=Doublet(radius=12.5,\n",
      "    curvature_s1 =1./61.47,\n",
      "    curvature_s2 =-1./44.64,\n",
      "    curvature_s3 =-1./129.94,\n",
      "    thickness_l1 = 6.,\n",
      "    thickness_l2 = 2.5,\n",
      "    material_l1  = N_BK7,\n",
      "    material_l2  = SF5)\n",
      "\n",
      "\n",
      "DB2=Doublet(radius=12.5,\n",
      "    curvature_s1 =1./61.47,\n",
      "    curvature_s2 =-1./44.64,\n",
      "    curvature_s3 =-1./129.94,\n",
      "    thickness_l1 = 6.,\n",
      "    thickness_l2 = 2.5,\n",
      "    material_l1  = N_BK7,\n",
      "    material_l2  = SF5)\n",
      "\n",
      "\n",
      "#Definition of a detector plane\n",
      "\n",
      "ccd=CCD()\n",
      "ccd1=CCD()\n",
      "\n",
      "# Place de tetectors at the focal planes of the lenses\n",
      "\n",
      "os=System(complist=[(DB1,(30,0,200),(0,0,0)),\n",
      "                    (DB2,(0,0,200),(pi,0,0)),\n",
      "                    (ccd,(30,0,float(400)),(0,0,0)),\n",
      "                    (ccd1,(0,0,400),(0,0,0))\n",
      "                    ],n=1)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "#Add the ray sources\n",
      "\n",
      "os.ray_add(r_b1)\n",
      "os.ray_add(r_b)\n",
      "\n",
      "os.propagate()\n",
      "\n",
      "display(plot3D(os,center=(0,0,200), size=(500,100),scale=2,rot=[(0,pi/2+.1,0),(-pi/4,0,0)]))\n",
      "\n",
      "display(spot_diagram(ccd))\n",
      "figure()\n",
      "display(spot_diagram(ccd1))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Par de dobletes"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L1=Edmund.get(\"45408\") ##f20,D5\n",
      "L2=Edmund.get(\"45407\")\n",
      "\n",
      "\n",
      "ccd=CCD(size=(15,15))\n",
      "\n",
      "spx=10.0*pi/180.\n",
      "spy=10.0*pi/180.\n",
      "\n",
      "R1=point_source_c(origin=(0, 0., -20), direction=(0., 0, 0), span=(spy, spx),num_rays=(10,10),wavelength=0.600 )\n",
      "\n",
      "\n",
      "S=System(complist=[(L1, (0, 0, 0), (0, 0, 0)),\n",
      "                (L2, (0, 0, 7), (0, 0, 0)),\n",
      "                (ccd, (0, 0, 25), (0, 0, 0)),\n",
      "                  \n",
      "                   ], n=1)\n",
      "\n",
      "\n",
      "S.ray_add(R1)\n",
      "S.propagate()\n",
      "spot_diagram(ccd)\n",
      "plot3D(S,center=(0,0,0), size=(80,30),scale=8,rot=[(0,-3*pi/8,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Lente Asf\u00e9rica"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "r_b= parallel_beam_c(size=(2,2),num_rays=(5,5), wavelength=.650)\n",
      "\n",
      "R=2.75\n",
      "k=-0.6139160\n",
      "A2=0\n",
      "A4=5.8891900E-04\n",
      "A6=-1.7660200E-05\n",
      "A8=1.0102500E-05\n",
      "A10=-3.9148700E-06\n",
      "\n",
      "\n",
      "r2=poly2d((0,0,0,1.,0,1.))\n",
      "r4=r2*r2\n",
      "r6=r4*r2\n",
      "r8=r4*r4\n",
      "r10=r8*r2\n",
      "\n",
      "poly=A2*r2+A4*r4+ A6*r6 +A8*r8 +A10*r10\n",
      "\n",
      "asf2=Aspherical(Kx=k, Ky=k, Ax=1./R,Ay=1./R, shape=Circular(radius=2.5),\n",
      "                                poly=poly)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "R=-3.1885400\n",
      "k=-12.6638600\n",
      "\n",
      "A2=0\n",
      "A4=1.2458340e-02\n",
      "A6=-3.7119450e-03\n",
      "A8=5.1223910e-04\n",
      "A10=-3.1085780e-05\n",
      "poly=A2*r2+A4*r4+ A6*r6 +A8*r8 +A10*r10\n",
      "\n",
      "asf1=Aspherical(Kx=k, Ky=k, Ax=1./R,Ay=1./R, shape=Circular(radius=2.5),\n",
      "                                poly=poly, reflectivity=.5)\n",
      "\n",
      "\n",
      "\n",
      "oc=Component(surflist=[(asf2, (0, 0, 0), (0, 0, 0)),\n",
      "                                           (asf1, (0, 0, 2.8+.35), (0,0, 0))\n",
      "                                           ],\n",
      "                                                material=1.58913)\n",
      "\n",
      "ccd=CCD(size=(3,3))\n",
      "\n",
      "\n",
      "\n",
      "os=System(complist=[(oc,(0,0,20),(0,0,0)),\n",
      "                                        (ccd,(0,0,20+2.8+2.14),(0,0,0)),\n",
      "                                        ],n=1)\n",
      "\n",
      "\n",
      "\n",
      "os.ray_add(r_b)\n",
      "os.propagate()\n",
      "\n",
      "\n",
      "display(plot3D(os,center=(0,0,10), size=(50,20),scale=16,rot=[(0,-3*pi/8,0)]))\n",
      "\n",
      "spot_diagram(ccd)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Lentes desalineadas"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "N_BK7=schott[\"BK7\"]\n",
      "N_BAK4=schott[\"BAK4\"]\n",
      "N_SF10=schott[\"SF10\"]\n",
      "\n",
      "\n",
      "\n",
      "# Definition of the ray sources at the origin\n",
      "\n",
      "# Blue\n",
      "#r_b= parallel_beam_c(size=(10,10),num_rays=(10,10), wavelength=.470)\n",
      "r_b=point_source_r(origin=(0.,0.,0.),direction=(0.,0.,0),span=pi/512\n",
      "                   ,num_rays=100,wavelength=0.470)\n",
      "\n",
      "# Green\n",
      "#r_g= parallel_beam_c(size=(10,10),num_rays=(10,10), wavelength=.540)\n",
      "r_g=point_source_r(origin=(0.,0.,0.),direction=(0.,0.,0),span=pi/512\n",
      "                   ,num_rays=100,wavelength=0.540)\n",
      "\n",
      "# Red\n",
      "#r_r= parallel_beam_c(size=(10,10),num_rays=(10,10), wavelength=.670)\n",
      "r_r=point_source_r(origin=(0.,0.,0.),direction=(0.,0.,0),span=pi/512\n",
      "                   ,num_rays=100,wavelength=0.670)\n",
      "\n",
      "# Definition\n",
      "oc=Doublet(radius=25,\n",
      "    curvature_s1 =1./162.59,\n",
      "    curvature_s2 =-1./123.82,\n",
      "    curvature_s3 =-1./402.58,\n",
      "    thickness_l1 = 9.75,\n",
      "    thickness_l2 = 3.50,\n",
      "    material_l1  = N_BAK4,\n",
      "    material_l2  = N_SF10)\n",
      "\n",
      "bs=BeamSplitingCube(size=50,material=N_BK7,reflectivity=0.5)\n",
      "\n",
      "#Definition of a detector plane\n",
      "\n",
      "ccd=CCD()\n",
      "\n",
      "\n",
      "# Place de tetectors at the focal planes of the lenses\n",
      "\n",
      "os=System(complist=[(oc,(0,0,500),(.50,0,0)),\n",
      "                    (ccd,(0,0,float(990)),(0,0,0)),\n",
      "                    (bs,(0,0,float(750)),(0,0,0)),\n",
      "                    ],n=1)\n",
      "\n",
      "#Add the ray sources\n",
      "os.ray_add(r_b)\n",
      "os.ray_add(r_g)\n",
      "os.ray_add(r_r)\n",
      "os.propagate()\n",
      "\n",
      "display(plot3D(os,center=(0,0,500), size=(1200,200),scale=1,rot=[(0,pi/2,0),(.3,0,0)]))\n",
      "\n",
      "spot_diagram_c(ccd)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Sistema con divisores de haz"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "N_BK7=schott['BK7']\n",
      "\n",
      "bs=BeamSplitingCube(size=8,material=N_BK7,reflectivity=0.5)\n",
      "\n",
      "L1=Edmund.get(\"45408\") ##f20,D5\n",
      "L2=Edmund.get(\"31861\")\n",
      "ccd=CCD(size=(10,10), transparent=False)\n",
      "\n",
      "\n",
      "spx=10.0*pi/180.\n",
      "spy=10.0*pi/180.\n",
      "\n",
      "R1=point_source_c(origin=(0, 0., -15), direction=(0., 0, 0), span=(spy, spx),num_rays=(10,10),wavelength=0.450 )\n",
      "\n",
      "\n",
      "S=System(complist=[(L1, (0, 0, 0), (0, 0, 0)),\n",
      "                   (bs, (0, 0, 15), (0, 0, 0)),\n",
      "                   (L2, (-10, 0, 15), (0, 90*pi/180., 0)),\n",
      "                   (bs, (-20, 0, 15), (90*pi/180., 0, 0))\n",
      "                   \n",
      "                   \n",
      "                   ], n=1)\n",
      "\n",
      "\n",
      "S.ray_add(R1)\n",
      "\n",
      "\n",
      "S.propagate()\n",
      "plot3D(S,center=(-15,0,7), size=(50,50),scale=16,rot=[(0,-pi/2,0),(-pi/2+.1,-pi/4,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "#Ejercicio:\n",
      "\n",
      "Simular un expansor de haz fabricado con 2 lentes esfericas de las siguientes caracteristicas:\n",
      "\n",
      "1. Lente convergente fabricada en BK7 de 50 mm de diametro con radios de curvatura 100 y -100 mm\n",
      "1. Lente convergente fabricada en BK7 de 50 mm de diametro con radios de curvatura 100 y -100 mm\n",
      "\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}